home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000526 / patchSG0000526.idb / usr / etc / configmail.z / configmail
Encoding:
Text File  |  1995-06-12  |  15.1 KB  |  745 lines

  1. #! /bin/sh
  2. #
  3. # Sendmail configuration functions.
  4.  
  5. CONFIGDIR=/etc
  6. UETC=/usr/etc
  7. SBIN=/usr/sbin
  8. MAILSCRIPT=/etc/init.d/mail
  9.  
  10. CONFIGOVRD=$CONFIGDIR/sendmail.params
  11. CONFIG=$UETC/configmail
  12.  
  13. # XXXrs - where does this go in the file reorg?
  14. PATHALIASDB=/usr/lib/news/maps/palias
  15.  
  16. CANONHOST="$SBIN/canonhost 2>&1"
  17.  
  18. HOSTNAME=/usr/bsd/hostname
  19. SHORTHOSTNAME="/usr/bsd/hostname -s"
  20.  
  21. SETUPPARAMS="forwarder rootdomain"
  22. NOTSETUPPARAMS="directdomains localdomain pathalias relayname"
  23. ALLPARAMS="$SETUPPARAMS $NOTSETUPPARAMS"
  24. FUNC="deadhosts domainrelay mycanonname"
  25.  
  26. NULLIND="[NULL]"
  27.  
  28. case "$1" in
  29.  
  30.  'help')
  31.     if test "$2" != "" && test "$2" != "usage"; then
  32.         sed -e "1,/START_$2_$1/ d" -e "/END_$2_$1/,\$ d" $0
  33.     else
  34.         echo
  35.         echo "Usage: $0 (help|get|set|unset <param>)"
  36.         echo
  37.         echo "Where <param> is one of:"
  38.         for param in $ALLPARAMS
  39.         do
  40.             echo "\t$param"
  41.         done
  42.         echo
  43.         echo "or: $0 (help|get <func>)"
  44.         echo
  45.         echo "Where <func> is one of:"
  46.         for func in $FUNC
  47.         do
  48.             echo "\t$func"
  49.         done
  50.         echo
  51.         echo "or: $0 (setup | list)"
  52.         echo
  53.         echo "Use \"$0 setup\" for quick sendmail set-up."
  54.         echo
  55.     fi
  56.     ;;
  57.  
  58.  'list')
  59.     ALL="$ALLPARAMS $FUNC"
  60.     echo
  61.     for pf in $ALL
  62.     do
  63.         result=`$CONFIG get $pf`
  64.         echo "$pf = \"$result\""
  65.     done
  66.     echo
  67.     ;;
  68.  
  69.  'get')
  70.  
  71.     case "$2" in
  72.  
  73.      'deadhosts')
  74.  
  75.         DEADHOSTFILE=$CONFIGDIR/sendmail.killed
  76.  
  77.         # List known dead hosts.  This is a list of all hosts in the
  78.         # domain for which this host is a forwarder.  If a message is
  79.         # received that is destined for one of these hosts, it will
  80.         # have the hostname stripped, and the username will be aliased
  81.         # in the hope of finding his new location.
  82.         #
  83.  
  84.         if test -r $DEADHOSTFILE; then
  85.             awk -F# '{if (length($1) != 0) print $1}' $DEADHOSTFILE
  86.         fi
  87.         echo "somewhere"
  88.         ;;
  89.  
  90.      'directdomains')
  91.  
  92.         if test -r $CONFIGOVRD; then
  93.             domain=`sed -n 's/directdomains:\(.*\)/\1/p' \
  94.                 $CONFIGOVRD`
  95.         fi
  96.         if test "$domain" = $NULLIND; then
  97.             exit 0
  98.         fi
  99.         if test "$domain" != ""; then
  100.             echo $domain
  101.             exit 0
  102.         fi
  103.  
  104.         myname=`$CONFIG get mycanonname`
  105.         mydomain=`$CONFIG get localdomain`
  106.         localfwdhost=`$CONFIG get domainrelay $mydomain`
  107.         if test $? != 0; then
  108.             exit 0
  109.         fi
  110.         canonlocalfwdhost=`eval $CANONHOST $localfwdhost`
  111.         if test $? = 0 &&
  112.            test "$myname" = "$canonlocalfwdhost"; then
  113.             $CONFIG get localdomain
  114.         fi
  115.         ;;
  116.  
  117.      'domainrelay')
  118.  
  119.         relayname=`$CONFIG get relayname`
  120.         if test "$3" != ""; then
  121.             relayhost=$relayname.$3
  122.         else
  123.             relayhost=$relayname
  124.         fi
  125.         canonrelayname=`eval $CANONHOST $relayhost`
  126.         if test $? = 0; then
  127.             echo $relayhost
  128.             exit 0
  129.         else
  130.             echo $canonrelayname
  131.             exit 1
  132.         fi
  133.         ;;
  134.  
  135.      'mycanonname')
  136.  
  137.         myname=`$SHORTHOSTNAME`
  138.         mydomain=`$CONFIG get localdomain`
  139.  
  140.         if test "$mydomain" != ""; then
  141.             echo "$myname.$mydomain"
  142.         else
  143.             echo "$myname"
  144.         fi
  145.         ;;
  146.  
  147.      'localdomain')
  148.  
  149.         # Determine the name of my domain.
  150.         #
  151.         # Try hostname command.  If that returns a hostname without
  152.         # domain, do gethostbyname on the name returned by the
  153.         # hostname command and return any domain found there.
  154.         #
  155.         # Return null if no domain found.
  156.  
  157.         if test -r $CONFIGOVRD; then
  158.             domain=`sed -n 's/localdomain:\(.*\)/\1/p' \
  159.                 $CONFIGOVRD`
  160.         fi
  161.         if test "$domain" = $NULLIND; then
  162.             exit 0
  163.         fi
  164.         if test "$domain" != ""; then
  165.                 echo $domain
  166.             exit 0
  167.         fi
  168.         hostname=`$HOSTNAME`
  169.         canonhostname=`eval $CANONHOST $hostname`
  170.         if test $? = 0; then
  171.             domain=`expr $canonhostname : '[^.]*\.\(.*\)'`
  172.             if test "$domain" != ""; then
  173.                 echo $domain
  174.             fi
  175.         fi
  176.         ;;
  177.  
  178.      'forwarder')
  179.  
  180.         # Determine the name of my forwarding host.  If no forwarding
  181.         # host is found, or if that host is me, return my name.
  182.  
  183.         if test -r $CONFIGOVRD; then
  184.             configfwdhost=`sed -n 's/forwarder:\(.*\)/\1/p' \
  185.                     $CONFIGOVRD`
  186.         fi
  187.         if test "$configfwdhost" != ""; then
  188.             if test "$configfwdhost" = $NULLIND; then
  189.                 exit 0
  190.             fi
  191.             if test "$3" = "-s"; then
  192.                 echo $configfwdhost | awk -F. '{print $1}'
  193.             else
  194.                     echo $configfwdhost
  195.             fi
  196.                 exit 0
  197.         fi
  198.  
  199.         canonthishost=`$CONFIG get mycanonname`
  200.  
  201.         # Try relay for root domain.
  202.  
  203.         rootdomain=`$CONFIG get rootdomain`
  204.         rootfwdhost=`$CONFIG get domainrelay $rootdomain`
  205.         if test $? = 0; then
  206.             canonrootfwdhost=`eval $CANONHOST $rootfwdhost`
  207.             if test $? = 0 &&
  208.                test "$canonrootfwdhost" != "$canonthishost"; then
  209.                 if test "$3" = "-s"; then
  210.                     echo $rootfwdhost | awk -F. '{print $1}'
  211.                 else
  212.                         echo $rootfwdhost
  213.                 fi
  214.                     exit 0
  215.             fi
  216.         fi
  217.  
  218.         # Try relay for local domain.
  219.  
  220.         mydomain=`$CONFIG get localdomain`
  221.         localfwdhost=`$CONFIG get domainrelay $mydomain`
  222.         if test $? = 0; then
  223.             canonlocalfwdhost=`eval $CANONHOST $localfwdhost`
  224.             if test $? = 0 &&
  225.                test "$canonlocalfwdhost" != "$canonthishost"; then
  226.                 if test "$3" = "-s"; then
  227.                     echo $localfwdhost | \
  228.                         awk -F. '{print $1}'
  229.                 else
  230.                         echo $localfwdhost
  231.                 fi
  232.                     exit 0
  233.             fi
  234.         fi
  235.  
  236.         # Try just "relay".
  237.  
  238.         rawfwdhost=`$CONFIG get domainrelay`
  239.         if test $? = 0; then
  240.             canonrawfwdhost=`eval $CANONHOST $rawfwdhost`
  241.             if test $? = 0 &&
  242.                test "$canonrawfwdhost" != "$canonthishost"; then
  243.                 if test "$3" = "-s"; then
  244.                     echo $rawfwdhost | awk -F. '{print $1}'
  245.                 else
  246.                         echo $rawfwdhost
  247.                 fi
  248.                     exit 0
  249.             fi
  250.         fi
  251.  
  252.         if test "$3" = "-s"; then
  253.             echo $canonthishost | awk -F. '{print $1}'
  254.         else
  255.                    echo $canonthishost
  256.         fi
  257.         ;;
  258.  
  259.      'pathalias')
  260.  
  261.         # Return the location of the pathalias database or /dev/null
  262.         # if none.
  263.  
  264.         if test -r $CONFIGOVRD; then
  265.             db=`sed -n 's/pathalias:\(.*\)/\1/p' $CONFIGOVRD`
  266.         fi
  267.         if test "$db" = $NULLIND; then
  268.             echo "/dev/null"
  269.             exit 0
  270.         fi
  271.         if test "$db" != ""; then
  272.             echo $db
  273.             exit 0
  274.         fi
  275.         if test -r $PATHALIASDB; then
  276.             echo $PATHALIASDB
  277.         else
  278.             echo "/dev/null"
  279.         fi
  280.         ;;
  281.  
  282.      'relayname')
  283.  
  284.         # Return the name used to denote relay hosts.  "relay" is
  285.         # suggested.
  286.  
  287.         if test -r $CONFIGOVRD; then
  288.             name=`sed -n 's/relayname:\(.*\)/\1/p' $CONFIGOVRD`
  289.         fi
  290.         if test "$name" = $NULLIND; then
  291.             echo "relay"
  292.             exit 0
  293.         fi
  294.         if test "$name" != ""; then
  295.             echo $name
  296.         else
  297.             echo "relay"
  298.         fi
  299.         ;;
  300.  
  301.      'rootdomain')
  302.  
  303.         # Determine the name of the top level domain.
  304.         #
  305.         # If none configured, use our domain name.
  306.  
  307.         if test -r $CONFIGOVRD; then
  308.             root=`sed -n 's/rootdomain:\(.*\)/\1/p' $CONFIGOVRD`
  309.         fi
  310.         if test "$root" != $NULLIND && test "$root" != ""; then
  311.             echo $root
  312.             exit 0
  313.         fi
  314.         if test -r $CONFIGOVRD; then
  315.             fwdr=`sed -n 's/forwarder:\(.*\)/\1/p' $CONFIGOVRD`
  316.             if test "$fwdr" != ""; then
  317.                 root=`expr $fwdr : '[^.]*\.\(.*\)'`
  318.             fi
  319.         fi
  320.         if test "$root" != ""; then
  321.             echo $root
  322.             exit 0
  323.         fi
  324.         $CONFIG get localdomain
  325.         ;;
  326.  
  327.      *)
  328.         $CONFIG help usage
  329.         ;;
  330.     esac
  331.     ;;
  332.  
  333.  'set'|'unset')
  334.  
  335.     uid=`id | sed 's/uid=\([0-9]*\).*/\1/'`
  336.     if test $uid != 0; then
  337.         echo "You must be super-user to $1 parameters."
  338.         exit 1
  339.     fi
  340.     if test ! -d $CONFIGDIR; then
  341.         echo $CONFIGDIR missing!
  342.         exit 1
  343.     fi
  344.     if test ! -f $CONFIGOVRD; then
  345.         echo "" > $CONFIGOVRD
  346.         if test $? != 0; then
  347.             echo "Cannot create $CONFIGOVRD."
  348.             exit 1
  349.         fi
  350.     fi
  351.     if test ! -w $CONFIGOVRD || test ! -r $CONFIGOVRD; then
  352.         echo "Cannot access $CONFIGOVRD."
  353.         exit 1
  354.     fi
  355.  
  356.     case "$2" in
  357.      'deadhosts'|\
  358.      'domainrelay'|\
  359.      'mycanonname')
  360.         echo
  361.         echo "$2 is a configmail function, not a true parameter."
  362.         echo "You cannot $1 $2."
  363.         echo "Use:"
  364.         echo
  365.         echo "\t$0 help $2"
  366.         echo
  367.         echo "for more information."
  368.         echo
  369.         ;;
  370.      'directdomains'|\
  371.      'localdomain'|\
  372.      'pathalias'|\
  373.      'rootdomain'|\
  374.      'forwarder'|\
  375.      'relayname')
  376.         if test "$1" = "set"; then
  377.             echo "=========="
  378.             $CONFIG help $2
  379.             current=`sed -n "s/$2:\(.*\)/\1/p" $CONFIGOVRD`
  380.         else
  381.             echo "Removing any override for $2."
  382.         fi
  383.         sed "/^$2:/d" $CONFIGOVRD > $CONFIGOVRD.tempfoo
  384.         mv $CONFIGOVRD.tempfoo $CONFIGOVRD
  385.         suggested=`$CONFIG get $2`
  386.         if test "$suggested" = ""; then
  387.             suggested=$NULLIND
  388.         fi
  389.         if test "$1" = "unset"; then
  390.             echo "Restored default for $2 is: $suggested."
  391.             if test "$current" != ""; then
  392.                 if test "$3" = "SUB"; then
  393.                     exit 2
  394.                 fi
  395.                 $CONFIG commit
  396.             fi
  397.             exit 0
  398.         fi
  399.         if test "$current" != ""; then
  400.             echo "Current setting: $current"
  401.         fi
  402.         echo "Suggested setting: $suggested"
  403.         echo
  404.         loop=1
  405.         while (test $loop = 1)
  406.         do
  407.             loop=0
  408.             if test "$current" != "" && \
  409.                test "$current" != "$suggested"; then
  410.                 echo "Enter new setting, \".\" for null ($current): \c"
  411.             else
  412.                 echo "Enter new setting, \".\" for null ($suggested): \c"
  413.             fi
  414.             read setting
  415.             if test "$setting" = ""; then
  416.                 if test "$current" != ""; then
  417.                     setting=$current
  418.                 else
  419.                     setting=$suggested
  420.                 fi
  421.             fi
  422.             if test "$setting" = "."; then
  423.                 setting=""
  424.             fi
  425.             if test "$setting" != "$current" &&\
  426.                test "$setting" != "$suggested"; then
  427.                 err=`$CONFIG verify $2 $setting`
  428.                 if test $? != 0; then
  429.                    echo
  430.                    echo "WARNING --- questionable setting of $2"
  431.                    echo "Reason: $err"
  432.                    echo
  433.                    echo "Use new setting anyway? (y|n): \c"
  434.                    read useit
  435.                    case "$useit" in
  436.                     'y'|'Y'|'y*'|'Y*')
  437.                     echo "Using new setting."
  438.                     break
  439.                     ;;
  440.                         *)
  441.                     echo "Abort new setting."
  442.                     loop=1
  443.                     ;;
  444.                    esac
  445.                 fi
  446.             fi
  447.         done
  448.         if test "$setting" = ""; then
  449.             setting=$NULLIND
  450.         fi
  451.         if test "$setting" != "$suggested"; then
  452.             echo "Setting $2 to: $setting"
  453.             echo
  454.             echo "$2:$setting" | cat - $CONFIGOVRD \
  455.                 > $CONFIGOVRD.tempfoo
  456.             mv $CONFIGOVRD.tempfoo $CONFIGOVRD
  457.             if test "$setting" = "$current"; then
  458.                 exit 0
  459.             fi
  460.             if test "$3" = "SUB"; then
  461.                 exit 2
  462.             fi
  463.             $CONFIG commit
  464.             exit 0
  465.         else
  466.             echo "Using $suggested for $2"
  467.             echo
  468.             if test "$current" != ""; then
  469.                 if test "$3" = "SUB"; then
  470.                     exit 2
  471.                 fi
  472.                 $CONFIG commit
  473.             fi
  474.             exit 0
  475.         fi
  476.         ;;
  477.  
  478.      *)
  479.         $CONFIG help usage
  480.         ;;
  481.  
  482.     esac
  483.     ;;
  484.  
  485.  'setup')
  486.  
  487.     changemade=0
  488.     for param in $SETUPPARAMS
  489.     do
  490.         $CONFIG set $param SUB
  491.         rtn=$?
  492.         if test $rtn = 1; then
  493.             exit 1
  494.         fi
  495.         if test $rtn = 2; then
  496.             changemade=1
  497.         fi
  498.     done
  499.     for param in $NOTSETUPPARAMS
  500.     do
  501.         current=`sed -n "s/$param:\(.*\)/\1/p" $CONFIGOVRD`
  502.         if test "$current" != ""; then
  503.  
  504.             $CONFIG set $param SUB
  505.             rtn=$?
  506.             if test $rtn = 1; then
  507.                 exit 1
  508.             fi
  509.             if test $rtn = 2; then
  510.                 changemade=1
  511.             fi
  512.         fi
  513.     done
  514.     echo
  515.     echo "=== SETUP COMPLETE ==="
  516.     echo
  517.     if test $changemade = 1; then
  518.         $CONFIG commit
  519.     fi
  520.     ;;
  521.  
  522.  'commit')
  523.     echo
  524.     echo "Changes have been made to the configuration.  To put these"
  525.     echo "changes into effect, you must restart sendmail."
  526.     echo
  527.     echo "Restart sendmail now? (y|n): \c"
  528.     read useit
  529.     case "$useit" in
  530.      'y'|'Y'|'y*'|'Y*')
  531.         echo
  532.         echo "Restarting sendmail..."
  533.         echo
  534.         $MAILSCRIPT start
  535.         ;;
  536.      *)
  537.         echo
  538.         echo "Sendmail has not been restarted.  The changes you made"
  539.         echo "may not take effect until sendmail is restarted."
  540.         echo
  541.         echo "Use: \"$MAILSCRIPT start\" to restart sendmail."
  542.         echo
  543.         ;;
  544.     esac
  545.     ;;
  546.  
  547.  'verify')
  548.     case "$2" in
  549.      'deadhosts'|\
  550.      'directdomains'|\
  551.      'domainrelay'|\
  552.      'localdomain'|\
  553.      'mycanonname'|\
  554.      'pathalias'|\
  555.      'relayname')
  556.         echo "OK"
  557.         ;;
  558.  
  559.      'forwarder')
  560.         # if the forwarder hostname cannot be canonicalized, complain.
  561.         if test "$3" != ""; then
  562.             fwdr=`echo $3`
  563.         else
  564.             fwdr=`$CONFIG get forwarder`
  565.         fi
  566.         if test "$fwdr" != ""; then
  567.             err=`eval $CANONHOST $fwdr`
  568.             if test $? != 0; then
  569.                 echo $err
  570.                 exit 1
  571.             fi
  572.         fi
  573.         echo "OK"
  574.         ;;
  575.  
  576.      'rootdomain')
  577.         # if the root domain is not some suffix of the local domain,
  578.         # complain.
  579.  
  580.         domain=`$CONFIG get localdomain`
  581.         if test "$3" != ""; then
  582.             rtdomain=`echo $3`
  583.         else
  584.             rtdomain=`$CONFIG get rootdomain`
  585.         fi
  586.         while (test "TRUE")
  587.         do
  588.             if test "$domain" = "$rtdomain"; then
  589.                 echo "OK"
  590.                 exit 0
  591.             fi
  592.             if test "$domain" = ""; then
  593.                 echo "Root Domain not suffix of Local Domain"
  594.                 exit 1
  595.             fi
  596.             domain=`expr $domain : '[^.]*\.\(.*\)'`
  597.         done
  598.         echo "Root Domain not suffix of Local Domain"
  599.         exit 1
  600.         ;;
  601.  
  602.      *)
  603.         $CONFIG help usage
  604.         ;;
  605.     esac
  606.     ;;
  607.  
  608.  *)
  609.     $CONFIG help usage
  610.     ;;
  611. esac
  612. exit 0
  613.  
  614. # Various help text blocks follow.  The START and END tags, in combination
  615. # with sed are used to display the selected block to the user when needed.
  616.  
  617. START_deadhosts_help
  618.  
  619. Dead Hosts:
  620.  
  621. This parameter is a list of all hosts in the local domain that
  622. no longer exist or are permanently "down" for whatever reason.
  623. This list will only be checked if the local host is a relay
  624. for the local domain.
  625.  
  626. The contents of this list is determined by the contents of the
  627. file $CONFIGDIR/sendmail.killed.
  628.  
  629. END_deadhosts_help
  630.  
  631. START_directdomains_help
  632.  
  633. Direct Domains:
  634.  
  635. This parameter is a list of all domains into which the local
  636. host should send mail directly (without the use of any
  637. forwarder, relay, or MX host).
  638.  
  639. If the local host is a relay or MX host for a particular
  640. domain, the name of that domain must appear in this list.
  641.  
  642. If the local host is not a relay or MX host, this parameter may
  643. be null.
  644.  
  645. END_directdomains_help
  646.  
  647. START_domainrelay_help
  648.  
  649. Domain Relay:
  650.  
  651. This is an internal function to configmail that returns
  652. the name of any relay host for the given domain name.
  653.  
  654. This is not a parameter and cannot be set.
  655.  
  656. END_domainrelay_help
  657.  
  658. START_forwarder_help
  659.  
  660. Forwarder Hostname:
  661.  
  662. This parameter must contain the name of the host that acts as
  663. the mail gateway between the local network and all foreign
  664. networks.  (As defined by the rootdomain parameter.)
  665.  
  666. Mail will be sent to the forwarder host whenever the destination
  667. host exists on the "other side" of the mail gateway, or whenever
  668. the local host cannot figure out how to deliver a particular
  669. message.
  670.  
  671. If no forwarder host exists, this parameter should be empty.
  672. If the local host is the forwarder host, this parameter should
  673. contain the local host's name.
  674.  
  675. END_forwarder_help
  676.  
  677. START_localdomain_help
  678.         
  679. Local Domain:
  680.  
  681. This parameter must contain the full local domain name.
  682.  
  683. If domain addressing is not used, this parameter should be null.
  684.  
  685. END_localdomain_help
  686.  
  687. START_mycanonname_help
  688.         
  689. My Canonical Name:
  690.  
  691. This is an internal function to configmail that returns
  692. the canonical name of the local host.
  693.  
  694. This is not a parameter and cannot be set.
  695.  
  696. END_mycanonname_help
  697.  
  698. START_pathalias_help
  699.         
  700. Pathalias Database:
  701.  
  702. This parameter must contain the location of the pathalias
  703. database used for UUCP mail routing.
  704.  
  705. If the local host does not do UUCP forwarding, or if pathalias
  706. is not used, this parameter should be set to /dev/null.
  707.  
  708. END_pathalias_help
  709.  
  710. START_relayname_help
  711.  
  712. Relay Host Name:
  713.  
  714. This parameter is the hostname or alias used for all relay
  715. machines.
  716.  
  717. END_relayname_help
  718.  
  719. START_rootdomain_help
  720.  
  721. Root Domain:
  722.  
  723. This parameter defines the boundary between the local and
  724. foreign networks.  All domain names that end in the root
  725. domain will be considered local domains and all hosts that
  726. exist in those domains will be considered part of the local
  727. network.  All other domains will be considered foreign domains
  728. and all hosts that exist in them will be considered to belong
  729. to foreign networks.
  730.  
  731. All mail addressed to hosts in foreign networks will be sent
  732. to the forwarder (mail gateway) host for delivery.
  733.  
  734. For example, if the root domain were set to "company.com", the
  735. domains "engr.company.com" and "mktg.company.com" would be
  736. considered to be local, while "othercompany.com" would be
  737. foreign.  Mail to hosts in any of the "company.com" domains
  738. would be delivered without the use of the forwarder host, while
  739. mail to any host "outside" the "company.com" domains would be
  740. routed through the forwarder.
  741.  
  742. If domain addressing is not used, this parameter should be null.
  743.  
  744. END_rootdomain_help
  745.